use actix_web::{HttpResponse, Responder, Result,get};
use serde::{Deserialize, Serialize};
use actix_web::web::Data;
use sqlx::{MySqlPool};

#[derive(Serialize, Deserialize)]
pub struct  Info {
    pub name: String,
    pub version: u32
}

pub async fn index() -> impl Responder {
    HttpResponse::Ok().body("home page!")
}


pub async fn info() -> Result<HttpResponse> {
    Ok(HttpResponse::Ok().json(Info {
        name: "obj.name".to_string(),
        version: 30
    }))
}

pub async fn info1() -> HttpResponse {
    HttpResponse::Ok().json(Info {
        name: "wuxie".to_string(),
        version: 18
    })
}

#[get("/serverinfo")]
pub async fn serverinfo() -> HttpResponse {
    HttpResponse::Ok().json(Info {
        name: "nnsword".to_string(),
        version: 40
    })
}

#[get("/readdata")]
pub async fn readdata(data: Data<MySqlPool>) -> HttpResponse {
    
    HttpResponse::Ok().json(Info {
        name: "nnsword".to_string(),
        version: 40
    })
}